package wzh.crm.ui.customer;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;

import wzh.crm.R;
import wzh.crm.ui.OverviewActivity;
import wzh.crm.vo.CustomerVo;

/**
 * Created by wangzehao on 2016/6/19.
 */
public class CustomerOverviewActivity extends OverviewActivity<CustomerVo> {

    @Override
    protected void displayModel() {
        setTitle(model.get客户名称());
        try {
            setDetails(getResources().getStringArray(R.array.客户类型)[model.get客户类型()-1]);
        }catch (Exception e){
            setDetails(getResources().getStringArray(R.array.客户类型)[model.get客户类型()]);
        }

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(CustomerOverviewActivity.this, CustomerDetailsActivity.class);
                i.putExtra("MODEL", model);
                CustomerOverviewActivity.this.startActivityForResult(i,REQUEST_CODE_MODEL);
            }


        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==REQUEST_CODE_MODEL&&resultCode==RESULT_OK){
            model= (CustomerVo) data.getSerializableExtra("MODEL");
            this.finish();
            data.setComponent(new ComponentName(this,CustomerOverviewActivity.class));
            startActivity(data);
        }
    }

    @Override
    protected void initTabHost(TabHost tabHost) {
        tabHost.addTab(tabHost.newTabSpec("tab跟进记录").setIndicator("跟进记录").setContent(R.id.tab跟进记录));
        tabHost.addTab(tabHost.newTabSpec("tab联系人").setIndicator("联系人").setContent(R.id.tab联系人));
        tabHost.addTab(tabHost.newTabSpec("tab商机").setIndicator("商机").setContent(R.id.tab商机));
        tabHost.addTab(tabHost.newTabSpec("tab合同").setIndicator("合同").setContent(R.id.tab合同));
    }
}
